/* contacts.js */

const app = getApp()

Page({
	data: {
		groups:[],
		friends:[],
		currentUser:{},
	},
	onLoad: function(options){
		// 好友列表改变
		app.globalData.imService.onFriendListChange = this.onFriendListChange;
	
		app.globalData.imService.onGroupListChange = this.onGroupListChange;
		this.setData({
			groups: app.globalData.imService.groups,
			friends: app.globalData.imService.friends,
			currentUser: app.globalData.imService.currentUser
		});
	},
	onUnload(){
		app.globalData.imService.disconnect();
	},
	enterPrivateChat (e) {//进入私聊
		var friend = e.currentTarget.dataset.friend;
		wx.navigateTo({
			url: `../privateChat/privateChat?friend=`+JSON.stringify(friend)
		});
	},
	enterGroupChat (e) {//进入群聊
		var group = e.currentTarget.dataset.group;
		wx.navigateTo({
			url: `../groupChat/groupChat?group=`+JSON.stringify(group)
		});
	},
	onFriendListChange(friendList){
		this.setData({
			friends:friendList
		});
	},
	onGroupListChange(groups){
		this.setData({
			groups: groups
		})
	}
})